﻿@using System.Text
@using OA.Model
@using OA.AspNetCore.Html
@using OA.Core.Model
@using OA.Core.Helper

@model OA.Model.DB.RelatedCompany
@{

    Layout = null;
    string msg = ViewBag.Msg;
    string tips = string.Empty;
    if (!string.IsNullOrWhiteSpace(msg))
    {
        tips = $"layer.msg('{msg}');";
    }
    BaseConfig config = ViewBag.BaseConfig;
     
}


<div class="layui-my-content">
    <div class="myForm">
        @using (Html.BeginForm(FormMethod.Post, htmlAttributes: new { @class = "layui-form", id = "myForm" }))
        {
            @Html.AntiForgeryToken()
            <div class="layui-form-item">
                @Html.LabelFor(model => model.Name, new { @class = "layui-form-label" })
                <div class="layui-input-block">
                    @Html.HiddenFor(model => model.ID)
                    @Html.MyEditorFor(model => model.Name)
                </div>
            </div>

            <div class="layui-form-item">
                @Html.LabelFor(model => model.NO, new { @class = "layui-form-label" })
                <div class="layui-input-block">
                    @Html.MyEditorFor(model => model.NO)
                </div>
            </div>

            <div class="layui-form-item">
                @Html.LabelFor(model => model.LegalPerson, new { @class = "layui-form-label" })
                <div class="layui-input-block">
                    @Html.MyEditorFor(model => model.LegalPerson)
                </div>
            </div>

            <div class="layui-form-item">
                @Html.LabelFor(model => model.BankOfDeposit, new { @class = "layui-form-label" })
                <div class="layui-input-block">
                    @Html.MyEditorFor(model => model.BankOfDeposit)
                </div>
            </div>

            <div class="layui-form-item">
                @Html.LabelFor(model => model.BankAccount, new { @class = "layui-form-label" })
                <div class="layui-input-block">
                    @Html.MyEditorFor(model => model.BankAccount)
                </div>
            </div>

            <div class="layui-form-item">
                @Html.LabelFor(model => model.Tel, new { @class = "layui-form-label" })
                <div class="layui-input-block">
                    @Html.MyEditorFor(model => model.Tel)
                </div>
            </div>

            <div class="layui-form-item myRegion">
                <label class="layui-form-label" for="AreaCode">所在地</label>
                <div class="layui-input-inline">
                    <select name="Province" class="Province" lay-filter="Province" lay-verify="required"></select>
                </div>
                <div class="layui-input-inline">
                    <select name="City" class="City" lay-filter="City" lay-verify="required"></select>
                </div>
                <div class="layui-input-inline">
                    <select name="District" id="District" class="Area" lay-filter="Area" lay-verify="required"></select>
                </div>
            </div>

            <div class="layui-form-item">
                @Html.LabelFor(model => model.Address, new { @class = "layui-form-label" })
                <div class="layui-input-block">
                    @Html.MyEditorFor(model => model.Address)
                </div>
            </div>


            <div class="layui-form-item">
                @Html.LabelFor(model => model.IsSupplier, new { @class = "layui-form-label" })
                <div class="layui-input-block">
                    @Html.MyEditorFor(model => model.IsSupplier)
                </div>
            </div>

            <div class="layui-form-item">
                @Html.LabelFor(model => model.IsCustomer, new { @class = "layui-form-label" })
                <div class="layui-input-block">
                    @Html.MyEditorFor(model => model.IsCustomer)
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <input type="submit" value="提 交" lay-submit="" lay-filter="OAForm" class="layui-btn mySubmit" />
                </div>
            </div>
        }
    </div>
</div>
<script type="text/javascript" src="@config.OssUrl/js/myarea.js"></script>
<script type="text/javascript">


    layui.use(['form','layer'], function () {
        var form = layui.form;
        var layer = layui.layer;
        form.on('select(Province)', function (data) {
            var parentCode = "";
            $.each(Areas, function (i, item) {
                if (item.type == 1 && data.value == item.name) {
                    parentCode = item.code;
                }
            });
            $(".myRegion").find(".City").find("option").remove();
            $(".myRegion").find(".City").append("<option value=''>请选择</option>");
            $(".myRegion").find(".Area").find("option").remove();
            $(".myRegion").find(".Area").append("<option value=''>请选择</option>");
            $.each(Areas, function (i, item) {
                if (item.parentCode ==parentCode) {
                   $(".myRegion").find(".City").append("<option data-value='"+item.code+"' value='" + item.name + "'>" + item.name + "</option>");
                }
            });
            form.render('select');
        });
        form.on('select(City)', function (data) {
            $(".myRegion").find(".Area").find("option").remove();
            $(".myRegion").find(".Area").append("<option value=''>请选择</option>");
            var cityCode = "";
            $.each(Areas, function (i, item) {
                if (item.type == 2 && data.value == item.name) {
                    cityCode = item.code;
                }
            });
            $.each(Areas, function (i, item) {
                if (item.parentCode == cityCode) {
                     $(".myRegion").find(".Area").append("<option data-value='"+item.code+"' value='" + item.name + "'>" + item.name + "</option>");
                }
            });
            form.render('select');
        });
        InitRegion($(".myRegion"), "@Html.Raw(Model.Province)", "@Html.Raw(Model.City)", "@Html.Raw(Model.District)");
        form.render('select');
    });
</script>